<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of common_service
 *
 * @author jirapatjantsakool
 */
require('../model/configure.php');

require('../util/apputil.php');

//require_once('../db/database.php');

class common_service
{

    public function validateTokenKey($db, $key, $nameKey)
    {

        if ($key === null || $key === '') {
            return FALSE;
        }

        $configure = new configure();

        $sql = 'select name, content '
            . ' FROM cf_configure '
            . ' where name = ? ';

        if ($stmt = $db->prepare($sql)) {

            mysqli_stmt_bind_param($stmt, 's', $nameKey);
            $db->execute_statement($stmt);

            $rowMaps = array();
            mysqli_stmt_bind_result($stmt, $rowMaps['name'], $rowMaps['content']);

            //TODO check number record
            if ($db->fetch_statement($stmt)) {
                $configure->setName($rowMaps['name']);
                $configure->setContent($rowMaps['content']);
            }
        }
        return ($key === $configure->getContent()) ? TRUE : FALSE;
    }
}

//$common_service = new common_service();
//$apputil = new apputil();
//var_dump($common_service->validateTokenKey('adfk','token'));
?>